<?php

namespace App\Http\Controllers\Api;

use App\City;
use App\Http\Resources\CityCollection;
use App\Http\Resources\CityResoure;
use App\Repository\CityRepository;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Overtrue\Pinyin\Pinyin;

class CityController extends Controller
{
    protected $cityRepository;
    public function __construct(CityRepository $cityRepository)
    {
        $this->cityRepository=$cityRepository;
    }

    /**
     * 获取城市切换列表
     */
    public function index(){
        $cityList= $this->cityRepository->getList();
        return  new CityCollection(collect($cityList));
    }
    /**
     * 获取城市下级区域信息
     * @param Request $request
     * @param $city_id
     * @return CityResoure
     */
    public function detail(Request $request,$city_id){
        $city=$this->cityRepository->details($city_id);
        return new CityResoure($city);
    }

    /**
     * @return CityResoure
     */
    public function defaultCity(){
        $city=City::where("is_hot",'1')->first();

        return new CityResoure($city);
    }


}
